package com.test.www.service;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

/**
 * <p>学生管理系统主页</p>
 * @author
 * 2020/12/16 22:26
 */
public class Home extends JFrame {
    JPanel jp1, jp2, jp3;
    public Home(){
        JFrame jFrame = new JFrame("学生成绩管理系统（主页）");

        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();
        JLabel jLabel = new JLabel("请选择你所需的功能");
        JButton jButton1 = new JButton("录入学生信息");
        JButton jButton2 = new JButton("查看学生信息");

        jFrame.setSize(850, 550);
        jFrame.setLocationRelativeTo(null);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);

        //将页面分成三行一列
        jFrame.setLayout(new GridLayout(3,1));
        //文字大小设置
        Font font=new Font("宋体",Font.BOLD,24);
        jLabel.setFont(font);
        jButton1.setFont(font);
        jButton2.setFont(font);
        // 学生信息录入
        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AddStudent();
                jFrame.dispose();
            }
        });

        // 查看学生信息
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new AllStudent(null);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                jFrame.dispose();
            }
        });

        jp1.add(jLabel);
        jp2.add(jButton1);
        jp3.add(jButton2);

        jFrame.add(jp1);
        jFrame.add(jp2);
        jFrame.add(jp3);

        jFrame.setVisible(true);
    }
}
